﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using KetBanBonPhuong;
using Tom;

public partial class UserControls_ResetPassword : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button_OK_Click(object sender, EventArgs e)
    {
        String Email = TextBox_Email.Text.Trim();
        if (String.IsNullOrEmpty(Email))
            Label_Result.Text = "Nhập Email";
        else
        {
            int UserID = User.GetUserbyEmail(Email);
            if (UserID == -1)
            {
                Label_Result.Text = "Email này chưa đăng ký.";
            }
            else
            {
                Random r = new Random();
                int password = r.Next(100000, 999999);
                User user = User.GetInfo(UserID);
                user.Password = Encrypt.MD5Encrypt(password.ToString());
                User.Update(user);

                Utils.SendPassword(Email, password.ToString());
                Label_Result.Text = "Mật khẩu đã được gửi vào email của bạn";
            }
        }
    }
}
